package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.Opinion;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 系统表的相关操作
 *
 * @author 魏骆淳 钟伟良
 */
@Repository
public interface SystemMapper {

    @Insert("insert into opinion(username, text) values (#{username}, #{opinionText})")
    void insertOpinionText(@Param("username") String username, @Param("opinionText") String opinionText);

    @Insert("insert into opinion_has_picture(opinion_id, picture) values (#{opinionId}, #{opinionPictureUrl})")
    void insertOpinionPicture(@Param("opinionId") long opinionId, @Param("opinionPictureUrl") String opinionPictureUrl);

    @Select("select datetime, id from opinion where id = last_insert_id()")
    Opinion selectOpinionDatetime();

    @Select("select  picture from opinion_has_picture where opinion_id = #{id}")
    List<String> selectOpinionPicture(Integer id);

    @Select("select  username,text,datetime,state from opinion where id = #{id}")
    Map<String, Object> selectOpinionText(Integer id);

    @Delete("Delete from opinion  where id=#{id}")
    void deleteOpinion(Integer id);

    @Select("SELECT id,username,datetime,text,state" +
            " FROM opinion where state LIKE #{state} and text LIKE #{name} ")
    List<Map<String, Object>> selectOpinionGeneral(String name, String state);
}
